<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var array1=[1,2,3,4,5];
        //获取array1数组中可枚举方法返回的对象
        var iter=array1[Symbol.iterator]();
        console.log(iter.next());  //{value: 1, done: false}
        console.log(iter.next());  //{value: 2, done: false}
        console.log(iter.next());  //{value: 3, done: false}
        console.log(iter.next());  //{value: 4, done: false}
        console.log(iter.next());  //{value: 5, done: false}
        console.log(iter.next());  //{value: undefined, done: true}

        //定义一个对象，实现Symbol.iterator接口，可以完成for...of循环
        var mall={
            products:["数码","生鲜","服饰"],
            [Symbol.iterator](){
                let i=0;
                let that=this;
                return {
                    next(){
                        if(i<that.products.length){
                            return {value: that.products[i++], done: false};
                        }else{
                            return {value: undefined, done: true};
                        }
                    }
                }
            }
        };

        for(let m of mall){
            console.log(m);
        }
    </script>
</body>
</html>